import multiprocessing

def square_sum(numbers, result_queue):
    """
    计算一组数字的平方和，并将结果存入队列中
    """
    square_sum = sum([num ** 2 for num in numbers])
    result_queue.put(square_sum)

if __name__ == '__main__':
    
    print([num ** 2 for num in numbers])

    # 创建进程池，最大进程数为4
    pool = multiprocessing.Pool(processes=4)

    # 定义一组数字
    numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

    # 创建多个子进程，并行计算平方和
    result_queue = multiprocessing.Queue()
    for i in range(4):
        start = i * len(numbers) // 4
        end = (i + 1) * len(numbers) // 4
        sub_numbers = numbers[start:end]
        pool.apply_async(square_sum, args=(sub_numbers, result_queue))

    # 等待所有子进程完成，并汇总结果
    pool.close()
    pool.join()
    square_sum = sum([result_queue.get() for i in range(4)])
    print(f"The square sum of numbers is {square_sum}")
